Java 8 Interview Questions and Answers
Question: Can you explain the syntax of Lambda expression?Answer:So we can divide structure of Lambda expression to three parts:
1. Argument list or parameters Lambda expression can have zero or more arguments. First part before '->' is called as argument list or parameters. ()->{System.out.println("Hello")}; //Without argument, will print hello (int a)->{System.out.println(a)} //; One argument, will print value of a (int a,int b)-> {a+b};//two argument, will return sum of these two integers 2. Array token (->) 3. Body
|
Is it helpful?
Yes
No
Most helpful rated by users:
- What are new features which got introduced in Java 8?
- What are main advantages of using Java 8?
- Can you explain the syntax of Lambda expression?
- What are functional interfaces?
- What Is a Default Method and When Do We Use It?